﻿using Clancy.Interfaces;
using System;
using System.Drawing;
using System.Reactive.Subjects;
using System.Threading.Tasks;

namespace Clancy.Bl.VideoProvider
{
    internal abstract class VideoSourceBase : IVideoSourceHandler
    {
        protected BehaviorSubject<Bitmap> IncomingFrame = new BehaviorSubject<Bitmap>(null);
        private readonly string m_MonikerString;

        protected VideoSourceBase(string monikerString)
        {
            m_MonikerString = monikerString;
        }

        public IObservable<Bitmap> IncomingBitmapFrame
        {
            get { return IncomingFrame; }
        }

        public async Task<bool> Close()
        {
            return await DoClose();
        }

        public async Task<bool> Open()
        {
            return await DoOpenVideoCapture(m_MonikerString);
        }

        public void ShowSettingsDialog()
        {
            DoShowSettingsDialog();
        }

        protected abstract Task<bool> DoClose();

        protected abstract Task<bool> DoOpenVideoCapture(string monikerString);

        protected abstract void DoShowSettingsDialog();
    }
}